//
//  PlatformWalletBill.m
//  reSearchDemo
//
//  Created by 科技 on 15/8/20.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "PlatformWalletBill.h"
#import "PlatformWalletBillCell.h"
#import "WalletBillModel.h"
@interface PlatformWalletBill () <UITableViewDataSource,UITableViewDelegate> {
    UITableView *_tableView;
    NSMutableArray *_dataSource;
    NSMutableArray *CellArr;
}

@end

@implementation PlatformWalletBill

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"钱包账单";
    
    WalletBillModel *model1 = [[WalletBillModel alloc] initWithName:@"服装" time:@"2014-12-4" money:@"200.00"];
    WalletBillModel *model2 = [[WalletBillModel alloc] initWithName:@"吃饭" time:@"2015-8-21" money:@"15.00"];
    WalletBillModel *model3 = [[WalletBillModel alloc] initWithName:@"话费" time:@"2015-5-6" money:@"50.00"];
    
    _dataSource = [NSMutableArray array];
    [_dataSource addObject:model1];
    [_dataSource addObject:model2];
    [_dataSource addObject:model3];
    
    CellArr = [NSMutableArray array];
    [_dataSource enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        PlatformWalletBillCell *cell = [[PlatformWalletBillCell alloc] init];
        [CellArr addObject:cell];
    }];
    
    [self initTableView];
}
#pragma mark --初始化tableview--
-(void)initTableView {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc] init];
    
    [self.view addSubview:_tableView];
}

#pragma mark -
#pragma mark --tableViewDelegate--
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *indentifier = @"cell";
    PlatformWalletBillCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        cell = [[PlatformWalletBillCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    cell.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:0.9];
    cell.model = _dataSource[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    PlatformWalletBillCell *cell = CellArr[indexPath.row];
    cell.model = _dataSource[indexPath.row];
    
    return cell.height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
